package com.iwe.crm.base.config;

import com.iwe.crm.base.filter.LoginFilter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CrmConfig implements WebMvcConfigurer {

    //配置登录拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器
        InterceptorRegistration interceptor =
                registry.addInterceptor(new LoginFilter());

        //拦截所有请求
        interceptor.addPathPatterns("/**");
        //排除拦截
        interceptor.excludePathPatterns(
                "/image/**",
                "/jquery/**",
                "/login",
                "/toLogin");
    }

    //配置上传文件映射路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:/d:/upload/");
    }
}
